#include<bits/stdc++.h>
using namespace std;
struct node{
    int a,b,c;
    double d,e,s;
}car[100001];
int t;

int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    cin>>t;
    for(int i=0;i<t;i++){
        int l,vm,n,m,cnt=0,ok;
        cin>>n>>m>>l>>vm;
        double le=0,lr=l,s;
        for(int j=0;j<n;j++){
            cin>>car[i].a>>car[i].b>>car[i].c;
            if(car[i].b>vm&&car[i].c>=0){
                if(car[i].b>vm){
                    lr=car[i].a;
                    cnt++;
                }
            }else if(car[i].c>0){
                s=((vm*vm-car[i].b*car[i].b)/2.0)/car[i].c;
                if(car[i].a+s<l){lr=s;continue;}
                if(le>car[i].a+s){le=car[i].a+s;cnt++;
                }
            }else if(car[i].c<0&&car[i].b>vm){
                s=((vm*vm-car[i].b*car[i].b)/2.0)/car[i].c;
                if(le>car[i].a)le=car[i].a+s;
                if(lr<car[i].a+s)lr=car[i].a+s;
                cnt++;
            }
        }
        cout<<cnt<<" ";
        cnt=0;
        for(int i=0;i<m;i++){
            int p;
            cin>>p;
            if(p>le&&p<lr){
                cnt++;
            }
        }
        cout<<cnt<<endl;
    }

    return 0;
}

